package com.fc.test.api;

import com.fc.test.model.auto.TAbbAixin;
import com.fc.test.service.TAbbAixinService;
import com.fc.test.util.JsonUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/apiDemoController")
@Api(value = "demo接口")
public class ApiDemoController {

    @Autowired
    private TAbbAixinService aixinService;

    @ResponseBody
    @PostMapping(value="getAixinByPage",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "demo分页查询爱心服务")
    @ApiResponses({
            @ApiResponse(code=200,message="获取数据成功",response = TAbbAixin.class),
    })
    public String getAixinByPage(
            @ApiParam(value = "页码") @RequestParam(value = "page") int page,
            @ApiParam(value = "1，同城互助；2，同城众筹；3，同城爱心") @RequestParam(value = "type") int type
    ){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbAixin> list = aixinService.getAixinByPage(page,type);
        if(list.size()>0){
            resMap.put("msg","获取爱心服务列表成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("list",list);
        resMap.put("success",true);
        return JsonUtil.jsonMapStr(resMap);
    }


}
